use serde::{Deserialize, Serialize};

use std::ops::Add;

#[derive(Eq, Hash, PartialEq)]
pub struct ResourceString {
    inner:String,
}

impl ResourceString {
    pub fn generate_resource_string(version:String,path:String) -> Self {
        let mut inner = version.clone();
        inner.push('&');
        inner = inner.add(path.as_str());

        ResourceString{ inner }
    }

    pub fn new(data:String) -> Self {
        ResourceString{ inner:data, }
    }

    pub fn version(&self) -> Option<String> {
        if !self.inner.contains("&") {
            return None;
        }

        let arr:Vec<&str> = self.inner.splitn(2,"&").collect();
        Some(arr[0].to_string())
    }

    pub fn path(&self) -> Option<String> {
        if !self.inner.contains("&") {
            return None;
        }

        let arr:Vec<&str> = self.inner.splitn(2,"&").collect();
        Some(arr[1].to_string())
    }
}

#[derive(Serialize, Deserialize,Clone)]
pub struct Resource{
    protocol:String,
    network:String,
    timeout:i32,
    path:String,
    port:i32,
    version:String,
}



pub struct PodResource{
    resource:Vec<Resource>,
    ip:String,
}